package com.masterclient.app.modules.order.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.masterclient.app.R;
import com.masterclient.app.base.MainViewHolder;
import com.eoner.baselibrary.bean.order.ConfirmOrderData;
import com.eoner.baselibrary.bean.order.CustomsClearanceMessage;

public class SubmitOrderCrossBorderAdapter extends DelegateAdapter.Adapter<MainViewHolder> {

    Activity mContext;

    private LayoutHelper mLayoutHelper;


    private VirtualLayoutManager.LayoutParams mLayoutParams;
    private int mCount = 0;

    ConfirmOrderData data;

    OnCrossBorderClick onCrossBorderClick;

    public OnCrossBorderClick getOnCrossBorderClick() {
        return onCrossBorderClick;
    }

    public void setOnCrossBorderClick(OnCrossBorderClick onCrossBorderClick) {
        this.onCrossBorderClick = onCrossBorderClick;
    }

    public interface OnCrossBorderClick{
        void OnItemClick();
    }


    public SubmitOrderCrossBorderAdapter(Activity context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, null,null);
    }

    public SubmitOrderCrossBorderAdapter(Activity context, LayoutHelper layoutHelper, int count, @NonNull VirtualLayoutManager.LayoutParams layoutParams, ConfirmOrderData data) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
        this.data = data;
    }
    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }
    @Override
    protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

    }

    @Override
    public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }
    @Override
    public void onBindViewHolder(MainViewHolder holder, int position) {
        if(mLayoutParams!=null) {
            holder.itemView.setLayoutParams(
                    new VirtualLayoutManager.LayoutParams(mLayoutParams));
        }

        TextView cross_border_name = holder.itemView.findViewById(R.id.cross_border_name);
        TextView cross_border_identity_card = holder.itemView.findViewById(R.id.cross_border_identity_card);
        View item = holder.itemView.findViewById(R.id.item);


        CustomsClearanceMessage customsClearanceMessage = data.getCustoms_clearance();
        if(customsClearanceMessage != null && !TextUtils.isEmpty(customsClearanceMessage.getReal_name())){
            cross_border_name.setText(customsClearanceMessage.getReal_name());
            cross_border_identity_card.setText(customsClearanceMessage.getIdentity_card());
        }else{
            cross_border_name.setText("新增实名认证");
            cross_border_identity_card.setText("购买直邮商品需要提供收货人身份证信息");
        }

        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onCrossBorderClick != null){
                    onCrossBorderClick.OnItemClick();
                }
            }
        });



    }


    @Override
    public int getItemCount() {
        return mCount;
    }

    @Override
    public int getItemViewType(int position) {
        return 8;
    }
}
